{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As far as I know, this idea is first raised by [Pavel Ostyakov](https://www.kaggle.com/c/jigsaw-toxic-comment-classification-challenge/discussion/48038)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "pip3 install textblob\n",
    "https://cloud.google.com/translate/docs/languages\n",
    "\"\"\"\n",
    "\n",
    "from textblob import TextBlob\n",
    "\n",
    "\n",
    "def parse(text, t_li, f):\n",
    "    text = TextBlob(comment)\n",
    "    return [str(text.translate(from_lang=f, to=t).translate(from_lang=t, to=f)) for t in t_li]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我非常喜欢这部电影，里面的情节非常好\n",
      "我很喜欢这部电影，剧情里面非常好\n",
      "我喜欢这部电影，剧情里面非常好\n"
     ]
    }
   ],
   "source": [
    "comment = '我很喜欢这部电影，里面的情节很棒'\n",
    "for res in parse(comment, ['en', 'es', 'ja'], 'zh-CN'):\n",
    "    print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This movie is a waste of time, meaningless to watch it\n",
      "this movie is a waste of time and it does not make sense to look at it\n",
      "This movie is a waste of time and there is no point to see it\n"
     ]
    }
   ],
   "source": [
    "comment = 'this movie is a waste of time and there is no point to watch it '\n",
    "for res in parse(comment, ['zh-CN', 'es', 'ja'], 'en'):\n",
    "    print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
